<?php
namespace App\Service\Pays;

use Yurun\PaySDK\AlipayApp\Params\PublicParams;

class Service
{
    // 配置
    public static $config = [];
    
    public function __construct($config)
    {
        static::$config = $config;
    }
    
    // 获取配置
    public static function config($name)
    {
        return static::$config[$name] ?? null;
    }
    
    // 支付宝
    public function alipay()
    {
        // 配置
        $config = static::config('alipay');
        
        // 传参数
        $params = new PublicParams;
        
        // 使用公钥证书模式
        $params->usePublicKeyCert = true;
        $params->appID = file_get_contents($config['appID']);
        $params->appPrivateKey = file_get_contents($config['appPrivateKey']);
        $params->appPublicKeyFile = $config['appPublicKeyFile'];
        $params->alipayCertPath = $config['alipayCertPath'];
        $params->alipayRootCertPath = $config['alipayRootCertPath'];
        $params->merchantCertPath = $config['merchantCertPath'];
        
        return new Alipay\Service($params, $config);
    }
}